// import fs from 'fs';
import { Parser, tokenizer } from 'acorn';
import { full } from 'acorn-walk';
import Tree from './tree';
import code from './code2.js?raw';
// const code = fs.readFileSync('./code.js', { encoding: "utf-8" });

const tokens = tokenizer(code, {})

console.log('token:', Array.from(tokens));

const ast = Parser.parse(code, {
    ecmaVersion: 2015
});

console.log('ast:', ast);

// walk.simple(ast, {
//     Literal(node) {
//         console.dir(node, { depth: 10 });
//     }
// })

// full(ast, (node, state, type) => {
//     console.dir(node, { depth:1 });
//     console.log(state, type);
// })

renderAst(document.getElementById('app'), ast);
document.getElementById('app')?.clientWidth

function renderAst(container, ast) {
    var svg = Tree(ast, {
        width: container.clientWidth,
        height: container.clientHeight,
        label: (node) => node.type,
    })
    container.appendChild(svg)
}
